package com.hotel.project.system.guestroom.controller;

import com.hotel.common.utils.poi.ExcelUtil;
import com.hotel.framework.aspectj.lang.annotation.Log;
import com.hotel.framework.aspectj.lang.enums.BusinessType;
import com.hotel.framework.web.controller.BaseController;
import com.hotel.framework.web.domain.AjaxResult;
import com.hotel.framework.web.page.TableDataInfo;
import com.hotel.project.system.guestroom.domain.GuestRoom;
import com.hotel.project.system.guestroom.service.IGuestRoomService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客房 信息操作处理
 *
 * @author pluto
 * @date 2019-04-06
 */
@Controller
@RequestMapping("/system/guestRoom")
public class GuestRoomController extends BaseController {
    private String prefix = "system/guestroom";

    @Autowired
    private IGuestRoomService guestRoomService;

    @RequiresPermissions("system:guestRoom:view")
    @GetMapping()
    public String guestRoom() {
        return prefix + "/guestRoom";
    }

    /**
     * 查询客房列表
     */
    @RequiresPermissions("system:guestRoom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GuestRoom guestRoom) {
        startPage();
        List<GuestRoom> list = guestRoomService.selectGuestRoomList(guestRoom);
        return getDataTable(list);
    }


    /**
     * 导出客房列表
     */
    @RequiresPermissions("system:guestRoom:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GuestRoom guestRoom) {
        List<GuestRoom> list = guestRoomService.selectGuestRoomList(guestRoom);
        ExcelUtil<GuestRoom> util = new ExcelUtil<GuestRoom>(GuestRoom.class);
        return util.exportExcel(list, "guestroom");
    }

    /**
     * 新增客房
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存客房
     */
    @RequiresPermissions("system:guestRoom:add")
    @Log(title = "客房", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GuestRoom guestRoom) {
        return toAjax(guestRoomService.insertGuestRoom(guestRoom));
    }

    /**
     * 修改客房
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        GuestRoom guestRoom = guestRoomService.selectGuestRoomById(id);
        mmap.put("guestRoom", guestRoom);
        return prefix + "/edit";
    }

    /**
     * 修改保存客房
     */
    @RequiresPermissions("system:guestRoom:edit")
    @Log(title = "客房", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GuestRoom guestRoom) {
        return toAjax(guestRoomService.updateGuestRoom(guestRoom));
    }

    /**
     * 删除客房
     */
    @RequiresPermissions("system:guestRoom:remove")
    @Log(title = "客房", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(guestRoomService.deleteGuestRoomByIds(ids));
    }

}
